package au.com.handsunited.web.controller.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import au.com.handsunited.model.User;
import au.com.handsunited.service.UserService;
import au.com.handsunited.web.session.SessionSupport;

/**
 * @author arunda
 *
 */
public class RemoveUserFromUserNetworkController extends AbstractController {


	private UserService userService;
	private String successView;

	private static Logger logger = LoggerFactory.getLogger(RemoveUserFromUserNetworkController.class);

	/**
	 *
	 */
	public RemoveUserFromUserNetworkController() {
	}

	/**
	 * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		String newUserId = request.getParameter("id");
		User currentUser = SessionSupport.getUser(request);

		ModelAndView mav = null;

		if (userService.removeUserFromNetwork(currentUser, newUserId)) {

			mav = new ModelAndView(successView, "entity", currentUser);
		} else {
			//	TODO User wasn't deleted so this has to be sent to the
			//	user as a message on the screen
		}

		return mav;
	}

	/**
	 * @param userService the userService to set
	 */
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	/**
	 * @param successView the successView to set
	 */
	public void setSuccessView(String successView) {
		this.successView = successView;
	}

}
